package com.example.administrator.autocompletetextviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;

public class MainActivity extends AppCompatActivity {

    private static final String[] autoStr = new String[] { "Italy","IT","item","its","itself"
            ,"abc","abcd","abcde"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //将autoStr字符串数组传入
        ArrayAdapter adapter =
                new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, autoStr);

        AutoCompleteTextView myAutoCompleteTextView =
                (AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
        myAutoCompleteTextView.setAdapter(adapter);

        MultiAutoCompleteTextView myMultiAutoCompleteTextView = (MultiAutoCompleteTextView)
                findViewById(R.id.myMultiAutoCompleteTextView);

        //以下两个方法要同时调用才不会出错
        myMultiAutoCompleteTextView.setAdapter(adapter);
        myMultiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    }
}
